import { defineStore } from "pinia";
import { Names } from "./names";
import type { RouteRecordRaw } from "vue-router";
import utils from "@/utils/utils";
// 使用options API模式定义
export const useCommpnStore = defineStore(Names.Common, {
    // 定义state
    state: () => {
        return {
            router: {} as RouteRecordRaw,
            adminId: ["631854801579df93e84f7cfd"],


            // style

            pageWidth: '' as any,
            directoryLeft: '' as any,
            mainHeight: '' as any,
            jumbotronHeight: '' as any,
            bottomHeight: '100px' as any,

        };
    },
    // 定义action
    actions: {
        //路由变化
        setRouter(router: any) {
            this.router = router
            this.setMainMinHeight()
        },
        //动态设置main的高度
        setMainMinHeight() {
            if (this.router.path == '/home') {
                this.jumbotronHeight = '500px'
            } else {
                this.jumbotronHeight = '400px'
            }
            this.mainHeight = `calc(100vh - ${this.jumbotronHeight} - ${this.bottomHeight})`
        },
        //页面宽变化执行
        changePageWidth(width: any) {
            this.pageWidth = width

            //宽度变化，设置目录定位
            const contentWidth = utils.getStyle('.content-warp', 'width')
            const positionLeft = (parseInt(contentWidth) / 2) + 'px'
            this.directoryLeft = `calc(50vw + ${positionLeft})`
        },


    },
    // 定义getters
    getters: {},
});
